package com.wyz.controller;

import com.github.pagehelper.PageInfo;
import com.wyz.entity.Grades;
import com.wyz.entity.Student;
import com.wyz.entity.Titletable;
import com.wyz.service.GradesService;
import com.wyz.service.StudentService;
import com.wyz.service.TitletableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class getHtmlController {
    @Autowired
    public StudentService studentService;
    @Autowired
    public GradesService gradesService;
    @Autowired
    public TitletableService titletableService;
    /**
     * 跳转班级管理
     * @return
     */
    @RequestMapping("addClass")
    public String addClass(){
        return "admin/classInfo";
    }
    @RequestMapping("addStudent")
    public String addStudent(Model model){
        PageInfo<Student> pageInfo = studentService.findAll(1, 5, "", null);
        model.addAttribute("pageInfo",pageInfo);
        List<Grades> gradesList = gradesService.findAll();
        model.addAttribute("grades",gradesList);
        return "studentList";
    }
    @RequestMapping("/addTitleTable")
    public String titletablePage(Model model){
        PageInfo<Titletable> pageInfo = titletableService.findAll(null, "", 1, 5);
        model.addAttribute("pageInfo",pageInfo);
        List<Grades> gradesList = gradesService.findAll();
        model.addAttribute("grades",gradesList);
        return "insertTestPaper";
    }
    @RequestMapping("addTitle")
    @ResponseBody
    public String addtitle(){
        Titletable titletable = null;
        for (int i=1;i<=100;i++){
            titletable = new Titletable();
            titletable.setName("测试题目"+i);
            titletable.setDescribe("测试简介");
            titletable.setAnswer_a("答案A"+i);
            titletable.setAnswer_b("答案B"+i);
            titletable.setAnswer_c("答案C"+i);
            titletable.setAnswer_d("答案D"+i);
            titletable.setJudgeopt(0);
            titletable.setExactness("A");
            titletable.setGrades(new Grades(1,"一年级"));
            titletable.setSetOpen("2020-12-30");
            System.out.println(titletable);
            titletableService.add(titletable);
        }
        return "添加成功";
    }
}
